package com.dy.controller;

import com.dy.pojo.User;
import com.dy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/4/8 9:47
 * @Version 1.0 (版本)
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/insert")
    public String insertUser(@RequestBody User user){
        System.out.println(user.getUname()+" "+user.getDatas());
        userService.insertUser(user);
        return "insert";
    }
    @DeleteMapping("/delete/{uid}")
    public String deleteUserById(@PathVariable Integer uid){
        System.out.println(uid);
        userService.deleteUserById(uid);
        return "delete";
    }
    @PutMapping("/update")
    public String updateUserById(@RequestBody User user){
        System.out.println(user.getUid());
        userService.updateUser(user);
        return "update";
    }
    @GetMapping("/selectById/{uid}")
    public User selectById(@PathVariable Integer uid){
        System.out.println(uid);
        User user1 = userService.selectById(uid);
        return user1;
    }
    @GetMapping("/select")
    public List<User> select(){
        List<User> users = userService.selectUser();
        return users;
    }
}
